﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTBLL;
using System.Data;

namespace XWG.JWBST.JWBSTManagementApp.Application
{
    public partial class TbBstOnlineAskVisitsManagement : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetMM();
            }
        }

        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="dt"></param>
        private void Bind(DataTable dt)
        {
            hc.DataSource = dt;
            hc.DataTextField = "DESCRIPTION";
            hc.DataValueField2 = "SL";
            hc.ChartHeight = 500;
            hc.ChartWidth = 800;
            hc.DataBind();
        }

        //按条件查询
        protected void BtnCheck_Click(object sender, EventArgs e)
        {
            string checktime = HttpContext.Current.Request.Form["texTime"];
            string begintime = HttpContext.Current.Request.Form["texTimeStart"];
            string endtime = HttpContext.Current.Request.Form["texTimeEnd"];

            if (!string.IsNullOrEmpty(checktime))
            {
                GetDD(checktime);
            }
            else if (!string.IsNullOrEmpty(begintime) && !string.IsNullOrEmpty(endtime))
            {
                GetDate(begintime, endtime);
            }
            else
            {
                GetMM();
            }
        }

        /// <summary>
        /// 按照具体时间点查询
        /// </summary>
        /// <param name="times"></param>
        public void GetDD(string times)
        {
            DataTable dt = new DataTable();
            dt = JWBSTBLL.TbBstOnlineAskVistBLL.GetAskNumByDD(times);
            if (dt.Rows.Count != 0)
            {
                Bind(dt);
            }
            else
            {
                Bindnull();
            }
        }

        /// <summary>
        /// 按照时间段查询
        /// </summary>
        /// <param name="begintime"></param>
        /// <param name="endtime"></param>
        public void GetDate(string begintime, string endtime)
        {
            DataTable dt = new DataTable();
            dt = JWBSTBLL.TbBstOnlineAskVistBLL.GetAskNumByDate(begintime, endtime);
            if (dt.Rows.Count != 0)
            {
                Bind(dt);
            }
            else
            {
                Bindnull();
            }
        }

        /// <summary>
        /// 查询当月
        /// </summary>
        public void GetMM()
        {
            DataTable dt = new DataTable();
            dt = JWBSTBLL.TbBstOnlineAskVistBLL.GetAskNumByMM(DateTime.Now.ToString("yyyy-MM"));
            if (dt.Rows.Count != 0)
            {
                Bind(dt);
            }
            else
            {
                Bindnull();
            }
        }

        private void Bindnull()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("SL");
            dt.Columns.Add("DESCRIPTION");
            List<string> listname = new List<string>();
            listname.Add("治安咨询");
            listname.Add("户政咨询");
            listname.Add("法制咨询");
            listname.Add("车管所咨询");
            listname.Add("交警咨询");
            listname.Add("禁毒咨询");
            listname.Add("经侦咨询");
            listname.Add("刑警咨询");
            listname.Add("出入境咨询");
            listname.Add("网警咨询");
            listname.Add("保安咨询");
            listname.Add("消防咨询");
            listname.Add("其他咨询");
            listname.Add("历下分局");
            listname.Add("市中分局");
            listname.Add("槐荫分局");
            listname.Add("天桥分局");
            listname.Add("历城分局");
            listname.Add("长清分局");
            listname.Add("章丘分局");
            listname.Add("平阴分局");
            listname.Add("济阳分局");
            listname.Add("商河分局");
            listname.Add("高新分局");
            listname.Add("鲍山分局");
            
            for (int i = 0; i < listname.Count; i++)
            {
                DataRow therow = dt.NewRow();
                therow["SL"] = 0;
                therow["DESCRIPTION"] = listname[i].ToString();
                dt.Rows.Add(therow);
            }

            hc.DataSource = dt;
            hc.DataTextField = "DESCRIPTION";
            hc.DataValueField2 = "SL";
            hc.ChartHeight = 500;
            hc.ChartWidth = 800;
            hc.DataBind();
        }
    }
}